package com.fyzk.activity.lottery.recommend_order;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ProgressBar;

import com.fyzk.base.BaseActivity;
import com.fyzk.activity.app.AppToast;
import com.tyjc.lottery.BuildConfig;
import com.tyjc.lottery.R;
import com.fyzk.view.TopTitleView;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import com.wf.domain.UrlDef;

/**
 * Created by fanxs11 on 17/7/4.
 */

@ContentView(R.layout.ac_certificationgod)
public class CertificationGodActivity extends BaseActivity {

    @ViewInject(R.id.certificationgod_topview)
    private TopTitleView topView;

    @ViewInject(R.id.powerlist_webview)
    private WebView webView;
    @ViewInject(R.id.powerlist_progress)
    private ProgressBar progressbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initView();

    }

    private String getUrl() {
        return UrlDef.followUrl + "shaidan/godv.html?source=" + BuildConfig.UPDATE_KEY;
    }

    private void initView() {
        topView.setOnTitleClickListener(this);

        WebSettings webSettings = webView.getSettings();
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setSaveFormData(false);
        // 必须要打开javaScript
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setSupportZoom(true);
        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                if (newProgress == 100) {
                    progressbar.setVisibility(View.GONE);
                } else {
                    if (progressbar.getVisibility() == View.GONE) {
                        progressbar.setVisibility(View.VISIBLE);
                    }
                    progressbar.setProgress(newProgress);
                }
                super.onProgressChanged(view, newProgress);
            }
        });
        webView.loadUrl(getUrl());
        webView.addJavascriptInterface(this,"android");//添加js脚本接口

    }

    @JavascriptInterface
    public void getUrl(final String usernum){
        Log.d(TAG, "goUserCenter: usernum"+usernum);
        AppToast.getToast().show(usernum);
        // todo...

    }
}
